<template>
	<div>
		<AplidForm ref="formRef" v-bind="BaseFormConfig" v-model="formModel" @submit="onSubmit" @reset="back"> </AplidForm>
	</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import apiMod from '@/apiMod'
import { uploadType } from '@/utils/util'
const emit = defineEmits(['refresh', 'back'])

type Props = {
	newData?: any
}
let props = withDefaults(defineProps<Props>(), {
	newData: {},
})

let formModel: any = {}
let formRef = ref()
formModel.headId = props.newData.id || ''
formModel.name = props.newData.staffName || ''
formModel.idCard = props.newData.idCard || ''
formModel.phone = props.newData.staffPhone || ''
formModel.jobType = props.newData.jobType || ''
formModel.jobTypeLabel = props.newData.jobTypeLabel || ''
// formModel.occupationType = props.newData. || ''

const limitStartDisabled = (date) =>{
	let now = (new Date()).getTime()
	let other = date.getTime()
	return other < now - 1000*60*60*24
}

let BaseFormConfig = {
	inline: false,
	labelPosition: 'left',
	labelWidth: 100,
	column: [
		{ label: '身份证号', prop: 'idCard', span: 12, rules: [{ required: true, message: '请填写身份证号' }] },
		{ label: '姓名', prop: 'name', span: 12, rules: [{ required: true, message: '请填写姓名' }] },
		{
			label: '请假类型',
			prop: 'leaveType',
			propName: 'leaveTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'LEAVEMANAGEMENT_LEAVE_TYPE',
			rules: [{ required: true, message: '请选择请假类型' }],
			span: 12,
		},
		{
			label: '开始时间',
			prop: 'leaveStartDate',
			type: 'datetime',
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			'disabled-date':limitStartDisabled,
			rules: [{ required: true, message: '请选择开始时间' }],
			span: 12,
		},
		{
			label: '结束时间',
			prop: 'leaveEndDate',
			type: 'datetime',
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			disabledDate:limitStartDisabled,
			rules: [{ required: true, message: '请选择结束时间' }],
			span: 12,
		},
		{ label: '备注', prop: 'note', span: 12, rules: [{ required: true, message: '请填写备注' }] },
		{
			label: '说明附件',
			prop: 'accessories',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			// listType: 'text',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
		},
	],
}

const onSubmit = (form, done) => {
	apiMod
		.view_dpEmployeeLeaveRecord_add(form)
		.then((res) => {
			done()
			emit('refresh')
		})
		.catch(() => {
			done()
		})
}
const back = () => {
	emit('back')
}

const onSave = () => {
	formRef.value!.onSubmit()
}
defineExpose({
	onSave,
})
</script>

<style scoped></style>
